
*	************************************************************************
* 	File-Name: 	prep.do
*	Log-file:	n/a
*	Date:  		21 Nov 2016
*	Author: 	Michael Aklin, Patrick Bayer, S.P. Harish, and Johannes Urpelainen
*	Data Used:  adoption_data.dta
*	Output		n/a
*	Purpose:   	file prepares raw data for analysis
*	************************************************************************

capture log close
clear all
set more off

use "./adoption_data.dta", clear

*	************************************************************************
*	A. Initial setup
*	************************************************************************

* Set data for panel analysis
* xtsetting
xtset Q11_hhid survey

* Revert MA's code for ITT for the Adoption paper
* This is because contaminated habitations are itt = 1 in the Adoption paper
replace itt = 1 if contamination == 1
replace tvitt = 1 if contamination == 1

* Drop all non-treatment HHs
keep if itt==1

* Drop if HHs flooded
keep if flooding==0


* Clean some village and hamlet names for consistency across survey waves
replace Q24_village="Akohara" if Q24_village=="Akohra"
replace Q25_hamlet="Ganga Purwa" if Q25_hamlet=="Gangapurwa" 
replace Q25_hamlet="Babapurwa" if Q25_hamlet=="Baba Purwa"
replace Q24_village="Basantapur" if Q24_village=="Basantpur"
replace Q25_hamlet="Kritpur Purwa" if Q25_hamlet=="Kiratpur Purwa"
replace Q25_hamlet="Pathan Basti" if Q25_hamlet=="Pathan Tola"
replace Q25_hamlet="Bhund Purwa" if Q25_hamlet=="Dund Purwa"
replace Q24_village="Karmullapur" if village_id==24
replace Q24_village="Karsa Kala" if Q24_village=="Karsa Kalan"
replace Q25_hamlet="Madhawpurwa" if Q25_hamlet=="Madhav Purwa"
replace Q25_hamlet="Katari Poorvi Tola" if Q25_hamlet=="Katari Purvi"
replace Q25_hamlet="Paschimi Tola" if Q25_hamlet=="Pakshim Tola"
replace Q25_hamlet="Lakhapur" if Q25_hamlet=="Lakkha Pur"
replace Q25_hamlet="Pokhai Purwa" if Q25_hamlet=="Pukhai Purwa"


*	************************************************************************
*	B. Variable creation and labels
*	************************************************************************

/* IMPORTANT: The lag2 variables are created to ensure that for the endline cross-section
all variables are measured pre-treatment. */

* Variables on solar lighting perceptions
gen L1quality = L1.Q102_quality 
gen L1reliability = L1.Q103_reliability
gen L1diff = L1.Q104_difficulty 
gen expend = Q105_expenditure
gen L1expend = L1.Q105_expenditure

gen L2quality = L2.Q102_quality 
gen L2reliability = L2.Q103_reliability
gen L2diff = L2.Q104_difficulty 
gen L2expend = L2.Q105_expenditure


label variable L1quality "Solar power improves lighting quality"
label variable L1reliability "Solar power improves lighting reliability"
label variable L1diff "Solar power is more difficult to use"
label variable L1expend "Solar power decreases lighting cost"

label variable L2quality "Solar power improves lighting quality"
label variable L2reliability "Solar power improves lighting reliability"
label variable L2diff "Solar power is more difficult to use"
label variable L2expend "Solar power decreases lighting cost"

gen L1mobile = Q81_mobilephone
label variable L1mobile "Number of mobile phones"

gen L1phonecharges = Q84_chargephone
label variable L1phonecharges "Weekly cost for phone charging"


* Variables on business activity/ risk taking
gen business = Q69_ownbusiness
gen L1business = L1.business
gen risk = riskindex
gen L1risk = L1.riskindex

gen L2business = L2.business
gen L2risk = L2.riskindex

label variable L1business "Business owner"
label variable L1risk "Entrepreneurial spirit"

label variable L2business "Business owner"
label variable L2risk "Entrepreneurial spirit"


* Variables on economic activity/ budget constraint
gen logexpenses = log(Q61_expenses+1)
drop logsavings
gen logsavings = log(Q62_savings+1)
gen debt = Q64_indebted
gen L1debt = L1.Q64_indebted

gen L1logsavings = L1.logsavings
gen L1logexpenses = L1.logexpenses

gen L2logsavings = L2.logsavings
gen L2logexpenses = L2.logexpenses
gen L2debt = L2.Q64_indebted

label variable L1logexpenses "HH expenditures (rupees/month, log)"
label variable L1logsavings "HH savings (rupees/month, log)"
label variable L1debt "HH in debt"

label variable L2logexpenses "HH expenditures (rupees/month, log)"
label variable L2logsavings "HH savings (rupees/month, log)"
label variable L2debt "HH in debt"


* Variables on electricity status
gen elec = Q91_electricity
gen L1elec = L1.Q91_electricity 

gen satisfaction = .
replace satisfaction = 5 if Q951_lightingsatis == 1
replace satisfaction = 4 if Q951_lightingsatis == 2
replace satisfaction = 3 if Q951_lightingsatis == 3
replace satisfaction = 2 if Q951_lightingsatis == 4
replace satisfaction = 1 if Q951_lightingsatis == 5

gen L1satisfaction = L1.satisfaction

gen L2elec = L2.Q91_electricity 
gen L2satisfaction = L2.satisfaction 

label variable L1elec "HH electrification"
label variable L1satisfaction "Lighting satisfaction"

label variable L2elec "HH electrification"
label variable L2satisfaction "Lighting satisfaction"


* Variables on kerosene prices and health hazards
gen logpublic = log(Q916_keroseneexpenses+1) 
gen logprivate = log(Q918_keroseneexpensesprivate+1) 
gen L1eyesight = L1.Q923_eyesight 
gen L1indoorair = L1.Q924_indoorair

gen L1logpublic = L1.logpublic
gen L1logprivate = L1.logprivate

gen L2logpublic = L2.logpublic
gen L2logprivate = L2.logprivate
gen L2eyesight = L2.Q923_eyesight 
gen L2indoorair = L2.Q924_indoorair


label variable L1logpublic "Kerosene spending (PDS, rupees/month, log)"
label variable L1logprivate "Kerosene spending (private, rupees/month, log)"
label variable L1eyesight "Bad eyesight"
label variable L1indoorair "Indoor air quality"

label variable L2logpublic "Kerosene spending (PDS, rupees/month, log)"
label variable L2logprivate "Kerosene spending (private, rupees/month, log)"
label variable L2eyesight "Bad eyesight"
label variable L2indoorair "Indoor air quality"


* Variables on HH characteristics
gen temp = 0
replace temp = 1 if Q39_married==1
gen size = 1+temp+Q314_malekids+Q316_femalekids
drop temp

gen L1size = L1.size
gen age = Q32_age
gen L1age = L1.Q32_age
gen educ = Q36_schoolyears
gen L1educ = L1.Q36_schoolyears

gen L2size = L2.size
gen L2age = L2.Q32_age
gen L2educ = L2.Q36_schoolyears

label variable L1size "HH size (\#)"
label variable L1age "Age of HH head"
label variable L1educ "School years of HH head"

label variable L2size "HH size (\#)"
label variable L2age "Age of HH head"
label variable L2educ "School years of HH head"


* Caste variable
gen castecat = .
replace castecat=1 if Q38_caste==1
replace castecat=2 if Q38_caste==3
replace castecat=3 if Q38_caste==2 | Q38_caste==4 | Q38_caste==5

label define castecatlabel 1 "Scheduled caste" 2 "Backward caste" 3 "Other"
label value castecat castecatlabel

gen scheduled=0
replace scheduled=1 if castecat==1
label variable scheduled "Scheduled caste"

gen L1scheduled=L1.scheduled
gen L2scheduled=L2.scheduled
label variable L1scheduled "Scheduled caste"
label variable L2scheduled "Scheduled caste"


gen backward=0
replace backward=1 if castecat==2
label variable backward "Backward caste"
gen L1backward = L1.backward
gen L2backward = L2.backward
label variable L1backward "Backward caste"
label variable L2backward "Backward caste"

gen other=0
replace other=1 if castecat==3
label variable other "Other caste"
gen L1other = L1.other
gen L2other = L2.other
label variable L1other "Other caste"
label variable L2other "Other caste"


* Labels for summary statistics
label variable logexpenses "HH expenditures (rupees/month, log)" 
label variable logsavings "HH savings (rupees/month, log)"
label variable debt "HH in debt"
label variable business "Business owner"
label variable risk "Entrepreneurial spirit"
label variable size "HH size (\#)"
label variable age "Age of HH head"
label variable educ "School years of HH head"
label variable elec "HH electrification"
label variable logpublic "Kerosene spending (PDS, rupees/month, log)"
label variable logprivate "Kerosene spending (private, rupees/month, log)"
label variable satisfaction "Lighting satisfaction" 
label variable expend "Solar power decreases lighting cost"

* Risk aversion variable from choice experiment
gen riskaverse = .
replace riskaverse = 4 if Q71_choiceC==1 & survey==1
replace riskaverse = 3 if Q71_choiceC==2 & survey==1
replace riskaverse = 2 if Q71_choiceB==2 & survey==1
replace riskaverse = 1 if Q71_choiceA==2 & survey==1

gen L1riskaverse = L1.riskaverse 
gen L2riskaverse = L2.riskaverse

label variable riskaverse "Risk aversion (experiment)"
label variable L1riskaverse "Risk aversion (experiment)"
label variable L2riskaverse "Risk aversion (experiment)"

* Trust variables

* In-group trust
gen trust_ingroup = Q163_ownreligion + Q164_owncaste
gen L1trust_ingroup = L1.trust_ingroup
gen L2trust_ingroup = L2.trust_ingroup
label variable trust_ingroup "In-group trust"
label variable L1trust_ingroup "In-group trust"
label variable L2trust_ingroup "In-group trust"

* Out-group trust
gen trust_outgroup = Q162_otherreligion + Q165_othercaste
gen L1trust_outgroup = L1.trust_outgroup
gen L2trust_outgroup = L2.trust_outgroup
label variable trust_outgroup "Out-group trust"
label variable L1trust_outgroup "Out-group trust"
label variable L2trust_outgroup "Out-group trust"

* Trust people in habitation
gen trust_hamlet = Q161_hamlet
gen L1trust_hamlet = L1.Q161_hamlet
gen L2trust_hamlet = L2.Q161_hamlet
label variable trust_hamlet "Trust people in habitation"
label variable L1trust_hamlet "Trust people in habitation"
label variable L2trust_hamlet "Trust people in habitation"

* Trust in large firms
gen trust_largefirms = Q1610_companies
gen L1trust_largefirms = L1.Q1610_companies
gen L2trust_largefirms = L2.Q1610_companies
label variable trust_largefirms "Trust large firms"
label variable L1trust_largefirms "Trust large firms"
label variable L2trust_largefirms "Trust large firms"

* Trust in small firms
gen trust_smallfirms = Q1611_smallfirms
gen L1trust_smallfirms = L1.Q1611_smallfirms
gen L2trust_smallfirms = L2.Q1611_smallfirms
label variable trust_smallfirms "Trust small firms"
label variable L1trust_smallfirms "Trust small firms"
label variable L2trust_smallfirms "Trust small firms"

* Trust in local firms
gen trust_localfirms = Q1612_areafirms
gen L1trust_localfirms = L1.Q1612_areafirms
gen L2trust_localfirms = L2.Q1612_areafirms
label variable trust_localfirms "Trust local firms"
label variable L1trust_localfirms "Trust local firms"
label variable L2trust_localfirms "Trust local firms"

* Trust index 1: Trust in people
gen trust_people_index = (trust_hamlet+trust_ingroup+trust_outgroup)/5
gen L1trust_people_index = L1.trust_people_index
gen L2trust_people_index = L2.trust_people_index

label variable trust_people_index "Trust in people (index)"
label variable L1trust_people_index "Trust in people (index)"
label variable L2trust_people_index "Trust in people (index)"


* Trust index 2: Trust in firms
gen trust_firms_index = (trust_largefirms+trust_smallfirms+trust_localfirms)/3
gen L1trust_firms_index = L1.trust_firms_index
gen L2trust_firms_index = L2.trust_firms_index

label variable trust_firms_index "Trust in firms (index)"
label variable L1trust_firms_index "Trust in firms (index)"
label variable L2trust_firms_index "Trust in firms (index)"


* Clean variable for reasons of non-adoption
gen MGPno = trim(Q93_MGPnoreason)
replace MGPno="Cost" if MGPno=="Due to lack of money" | MGPno=="SHE CANN'T PAY THE BILL,IT IS VERY EXPENSIVE." | MGPno=="MONEY IS MORE OS CAN`T MGP" | ///
MGPno=="IT IS BEYOND OUR BUDGET." | MGPno=="UNABLE TO PAY" | MGPno=="It is too expensive" | MGPno=="IT IS EXPENSIVE" | ///
MGPno=="HE HAS NO MONEY" | MGPno=="LOW INCOME" | MGPno=="FINANCIAL CONDTION IS NOT WELL" | MGPno=="MONEY PROBLEM" | ///
MGPno=="EXPENSIVE AMOUNT" | MGPno=="DUE TO POVERTY" | MGPno=="FINANCIAL PROBLEM" | MGPno=="HE CAN NOT DEPOSITE MONEY" | ///
MGPno=="HE HAS A BATTERY AND UNABLE TO PAY BILL" | MGPno=="HE HAS NO MONEY TO GIVE." | MGPno=="HE IS UNABLE TO PAY BILL" | ///
MGPno=="HE IS UNABLE TO PAY RS.100 FOR MGP." | MGPno=="HE WAS UNABLE TO GIVE THE MONEY" | MGPno=="HE WAS UNABLE TO PAY BILL" | ///
MGPno=="HIS FINANCIAL CONDITION IS NOT WELL" | MGPno=="IT IS BEYOND THE BUDGET" | MGPno=="IT IS BEYOND THE BUDGET." | ///
MGPno=="IT IS VERY EXPENSIVE" | MGPno=="Instalment amount is too much." | MGPno=="LESS INCOME" | ///
MGPno=="NO MONEY" | MGPno=="NOT GIVING THE MONEY" | MGPno=="SHE HAS NO MONEY TO GIVE." | ///
MGPno=="SHE IS UNABLE TO PAY RS.100 FOR MGP." | MGPno=="USAGE BILL WOULD BE EXPENSIVE" | ///
MGPno=="SHE IS VERY POOR SO SHE IS NOT ABLE TO TAKE MGP." | MGPno=="HE IS UNABLE TO PAY RS.100."



replace MGPno="Already other option" if MGPno=="HE HAS GRID ELECTRICITY." | MGPno=="Already have Grid Electricity" | ///
MGPno=="I have already connection" | MGPno=="I want to take connection of Grid Electricity" | MGPno=="SHE HAS SOLAR SYSTEM" | ///
MGPno=="Already have solar home system" | MGPno=="Already have batteries electricity" | MGPno=="HE HAS SOLAR SYSTEM." | ///
MGPno=="SOLAR SYSTEM" | MGPno=="ALREDY HAS BATTERY" | MGPno=="HE HAVE BATTERY" | MGPno=="ALREADY HAVE ELECTRICITY." | ///
MGPno=="GOVT LIGHT" | MGPno=="HE ALREADY HAS BATTERY" | MGPno=="HE HAD A SOLAR SYSTEM" | MGPno==" HE HAS BATTERY" | ///
MGPno=="HE HAS BATTERY." | MGPno=="HE HAS GOVERNMENT ELECTRICITY." | MGPno=="HE HAS GRID ELECTRICITY" | ///
MGPno=="HE HAS SOLAR SYSTEM" | MGPno=="HE HAS SOLAR SYTEM" | MGPno=="SHE HAS BATTERY" | MGPno=="SHE HAS GRID ELECTRICITY." | ///
MGPno=="HE HAS BATTERY" | MGPno=="ALREADY HAVE BATTERY AND GRID ELECTRICITY" | MGPno=="HE HAS OWN SOLAR SYSTEM" | MGPno=="HE HAS SOLAR HOME CONNECTION"



replace MGPno="Problem with MGP" if MGPno=="MGP do not provide electricity properly" | ///
MGPno=="DIDN'T COME AGAIN" | MGPno=="NOT COME AGAIN" | MGPno=="MGP's officer have not come again." | ///
MGPno=="MGP did not give connection" | MGPno=="MGP'S LIGHT NOT GOOD" | MGPno=="Due to dispute with MGP officer" | ///
MGPno=="THEY HAD NOT ENOUGH CABLE FOR THE CONNECTION" | MGPno=="we can not get trustable electricity from MGP" | ///
MGPno=="MGP did not give connection" | MGPno=="NOT RELIABLE" | MGPno=="DIDN'T COME AGAIN" | MGPno=="LIGHT IS NOT GOOD" | ///
MGPno=="DON'T TRUST MGP" | MGPno=="HAD A FIGHT WITH THE MGP PEOPLE" | MGPno=="MGP LIGHT IS NOT GOOD" | MGPno=="MGP NOT GIVE THE CONNECTION" | ///
MGPno=="MGP SERVICE IS NOT GOOD" | MGPno=="MGP SERVICE IS NOT UNDERSTANDING." | MGPno=="MGP WAS NOT REDDY TO GIVE ONLY ONE BULB" | ///
MGPno=="NOT RELIBLE" | MGPno=="THEY WEEKLY TAKE MONEY" | MGPno=="TAKE THE MONEY BUT NOT GIVE THE CONNECTION" | MGPno=="MGP's officer already gave electricity to 10 house." | ///
MGPno=="MGP did not give connection because they have already given connection of 10 houses." | MGPno=="HE GIVE FIFTTY RUPES BUT THEY NOT COME BACK"

replace MGPno="Problem with MGP" if MGPno=="CAME ONLY FOR ONCE THEN NO ONE CAME AFTER THAT" | MGPno=="CAME ONLY FOR ONCE THEN NO CAME  AFTER THAT" | ///
MGPno=="DON'T LIKE MGP" | MGPno=="MGP DID NOT GIVE THE CONNECTION" | MGPno=="MGP LIGHT IS NOT REGULAR" | MGPno=="MGP'S WORKING POLICY IS NOT GOOD" | MGPno=="THEY COME EVERY WEEK FOR TAKING MONEY" | ///
MGPno=="AFTER TAKING RS.50 DIDN'T GAVE THE CONNECTION" | MGPno=="MONEY DEPOSITED BUT DID'T GIVE CONNECTION" | MGPno=="MONEY DEPOSITED BUT MGP DIDN'T GIVE THE CONNECTION" | MGPno=="GAVE RS.50 FOR THE CONNECTION BUT DIDN`T GET IT"


replace MGPno="Other" if MGPno=="AGAST" | MGPno=="DON'T WANT" | MGPno=="HOUSE IS NOT GOOD" | ///
MGPno=="NOT UNDERSTANDING" | MGPno=="NO ONE TAKE IT IN VILLAGE" | MGPno=="Villagers denied to take connection" | ///
MGPno=="DON'T UNDERSTAND" | MGPno=="HE DOESN'T TAKE CONNECTION" | MGPno=="0" | MGPno=="DIDN`T GET THE CONNECTION" | ///
MGPno=="HE WANT GOVT ELECTRICITY" | MGPno=="JUST CAME IT ASK BUT DIDN`T INSTALL" | MGPno=="NO BENIFIT" | ///
MGPno=="NOT AGREE" | MGPno=="OTHER PEOPLE WERE NOT AGREE" | MGPno=="OTHER PERSON WERE NOT AGREE" | MGPno=="OTHER PERSONS WERE NOT REDDY." | ///
MGPno=="HE HAD THE FEAR THAT MGP INSTRUMENTS WOULD BE STOL" | MGPno=="BECAUSE OF THE BROKEN HOUSE CANN`T TAKE  CONNECTION"

label variable MGPno "Reasons for non-adoption"

gen MGPlacksupport = 0
replace MGPlacksupport = 1 if trim(Q93_MGPnoreason)=="NO ONE TAKE IT IN VILLAGE" | trim(Q93_MGPnoreason)=="Villagers denied to take connection" | trim(Q93_MGPnoreason)=="OTHER PEOPLE WERE NOT AGREE" | trim(Q93_MGPnoreason)=="OTHER PERSON WERE NOT AGREE" | trim(Q93_MGPnoreason)=="OTHER PERSONS WERE NOT REDDY."




* Recode variable for reasons to discontinue MGP service
gen discont_reason = ""
replace discont_reason = "Conflict with MGP" if Q981_MGPdiscontinuereason=="Due to bad management"
replace discont_reason = "Conflict with MGP" if Q981_MGPdiscontinuereason=="Due to delay payment"
replace discont_reason = "Conflict with MGP" if Q981_MGPdiscontinuereason=="Due to dispute with MGP officer"
replace discont_reason = "Conflict with MGP" if Q981_MGPdiscontinuereason=="MGP DISCONTINUED WITH THIS SERVICE"
replace discont_reason = "Conflict with MGP" if Q981_MGPdiscontinuereason=="MGP WORKERS BEHAVIOUR IS NOT GOOD"
replace discont_reason = "Conflict with MGP" if Q981_MGPdiscontinuereason=="THE WAY OF TAKING MONEY WAS BAD"
replace discont_reason = "Conflict with MGP" if Q981_MGPdiscontinuereason=="MGP have not provide electricity properly"
replace discont_reason = "Conflict with MGP" if Q981_MGPdiscontinuereason=="MGP have not provide electricity Properly"
replace discont_reason = "Conflict with MGP" if Q981_MGPdiscontinuereason=="THEY WERE TAKING BILL AT 28 DAYS AND HE WANT TO GIVE THE BILL AT 30DAYS"

replace discont_reason = "Cost" if Q981_MGPdiscontinuereason=="Due to lack of money"
replace discont_reason = "Cost" if Q981_MGPdiscontinuereason=="IT IS VERY EXPENSIVE"
replace discont_reason = "Cost" if Q981_MGPdiscontinuereason=="Due to lack of money"
replace discont_reason = "Cost" if Q981_MGPdiscontinuereason=="Due to lack of money"

replace discont_reason = "Quality" if Q981_MGPdiscontinuereason=="LIGHT IS NOT GOOD."
replace discont_reason = "Quality" if Q981_MGPdiscontinuereason=="LIGHT IS NOT REGULAR"
replace discont_reason = "Quality" if Q981_MGPdiscontinuereason=="LIGHT WAS NOT GOOD"
replace discont_reason = "Quality" if Q981_MGPdiscontinuereason=="MACHINE IS NOT WORKING"
replace discont_reason = "Quality" if Q981_MGPdiscontinuereason=="Panel was break before two months"
replace discont_reason = "Quality" if Q981_MGPdiscontinuereason=="MACHINE IS NOT WORKING"
replace discont_reason = "Quality" if Q981_MGPdiscontinuereason=="MGP provide electricity only two days in a week"

replace discont_reason = "Conflict with neighbors" if Q981_MGPdiscontinuereason=="Due to dispute with neighbours"

replace discont_reason = "Other" if Q981_MGPdiscontinuereason=="ONLY USED 3 MONTHS"

*	************************************************************************
*								END OF DO FILE 
*	************************************************************************



